<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="com.bean.LoginBean"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

<%Class.forName("com.mysql.jdbc.Driver").newInstance(); 
String url="jdbc:mysql://localhost:3306/graduatedesign";  
String user="root";  
String password="root";
LoginBean LoginBean= (LoginBean)session.getAttribute("Loginbean");
Connection conn = DriverManager.getConnection(url, user, password); 
Statement sm=conn.createStatement();
String oldpassword="";
ResultSet rs=sm.executeQuery("select password from user where username='"+LoginBean.getUsername()+"'"); 
String username=LoginBean.getUsername();
if(rs.next())
{   oldpassword=rs.getString(1);
}
%>
   <script language="javascript">
        document.register.password.focus();
        function test(){
             var f=document.register;
             var newPsw =document.getElementById("password").value;
             var newPsw1 =document.getElementById("password1").value;
             var newPsw2 =document.getElementById("password2").value;
             var oldPsw= "<%=oldpassword%>";
             if(newPsw1 == "" || newPsw2 == "" ||newPsw == "" ){
                  alert("密码框不能为空!");
                  f.password.value='';
                  f.password1.value='';
                  f.password2.value='';
                  return false;
             }
             if(newPsw != oldPsw){
                  alert("旧密码错误！");
                  f.password.value='';
                  f.password1.value='';
                  f.password2.value='';
                  return false;
             }
             if(newPsw1 != newPsw2){
                  alert("两次密码输入不一致!");
                  f.password.value='';
                  f.password1.value='';
                  f.password2.value='';
                  return false; 
             }
              if(newPsw == newPsw1){
                  alert("新旧密码不能一样!");
                  f.password.value='';
                  f.password1.value='';
                  f.password2.value='';
                  return false;
             }
             alert("修改成功！");
             return true;
        }
       
    </script>
  </head>
  
  <body>

    
        <center>
           <form method="post" name="register" action="changepass?username=<%=username%>">
              <table>
                  <tr><th colspan="3">密码修改</th></tr>
                  <tr>
                     <td>输入旧密码：<td>
                     <td><input id="password" name="password" type="text"  onfocus="this.type='password'"/></td>
                  </tr>
                  <tr>
                     <td>输入新密码：<td>
                     <td><input id="password1" name="password1" type="text"  onfocus="this.type='password'"/></td>
                  </tr>
                  <tr>
                     <td>请再次输入：<td>
                     <td><input id="password2" name="password2" type="text"  onfocus="this.type='password'"/></td>
                  </tr>
              </table>
              <input name="chapsubmit" value="提 &nbsp; 交" type="submit" onclick="return test()"/>
           </form>
        </center>
  </body>
</html>
